//1.工厂模式
function createPlayer(color) {
  const Player = new Object()
  Player.color = color
  Player.start = function () {
    console.log("下棋")
  }
  return Player
}
const red = createPlayer("red")
const a = createPlayer("1")
const b = createPlayer("1")
//缺点 无法判断类型

//2.构造函数/实例
function Player() {
  this.color = "red"
}
const p1 = new Player()
//缺点 每生成一个实例，构造函数内部的方法都会重新开辟一块内存

//3.原型
function Player() {
  this.color = "red"
}
Player.prototype.start = function () {
  console.log("111111")
}

// iterator
var inHomeYou = {
  cursor: 0,
  next() {
    const actions = ["抖音", "none纲要", "吃饭", "睡觉"]
    if (this.cursor > 7) {
      return {
        done: false,
      }
    }
    return {
      done: false,
      value: actions[this.cursor++ % actions.length],
    }
  },
  [Symbol.iterator]: function () {
    return this
  },
}

var obj = {}
Object.defineProperty(obj, "money", {
  get(key) {
    console.log("get le ")
    return obj[key]
  },
  set(key, val) {
    console.log("set le ")
    return (obj[key] = val)
  },
})

//proxy

var ProxyObj = new Proxy(
  {},
  {
    get(target, key, recevicer) {
      console.log("key:", key)
    },
    set(target, key, val, recevicer) {
      console.log("key:", key, val)
    },
  }
)
